package tmt.usercenter.web.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import lombok.Getter;
import lombok.Setter;
import tmt.usercenter.web.domain.converter.JsonNodeConverter;
import tmt.usercenter.web.domain.enums.TmtOauthType;

import javax.persistence.*;
import java.io.Serializable;

/**
 * 外部登录账号
 * Created by Stark on 2017/3/1.
 */
@Getter
@Setter
@Entity
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
@JsonIdentityInfo(generator = JSOGGenerator.class)
public class TmtOauthAccount extends BaseDomain implements Serializable {

	/** 认证类型 */
	@Enumerated(EnumType.STRING)
	private TmtOauthType authType;

	/** 认证账号 */
	private String authId;

	/** 是否可用 */
	@Column(nullable = false, columnDefinition = "TINYINT", length = 1)
	private boolean enabled;

	/** oauth2 认证后获取，保存 json 格式数据，方便以后 */
	@Column(length = 2000)
	@Convert(converter = JsonNodeConverter.class)
	private JsonNode detail;

	@ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
	private TmtUser tmtUser;
}
